#include "AccountIdGenerator.hh"
#include <random>
#include <sstream>

namespace mini_bank {

std::string AccountIdGenerator::genDigits(int len) {
    std::uniform_int_distribution<> d(0, 9);
    static thread_local std::mt19937 gen(std::random_device{}());
    std::ostringstream ss;
    while (len--) ss << d(gen);
    return ss.str();
}

std::string AccountIdGenerator::generate(const std::string& typeCode) {
    std::string id;
    do {
        id = "62" + typeCode + "-" + genDigits(4) + "-" + genDigits(4) + "-" + genDigits(4);
    } while (usedIds.count(id));
    usedIds.insert(id);
    return id;
}

} // namespace mini_bank
